package com.example.studyktdemo.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.studyktdemo.bean.ItemX
import com.example.studyktdemo.databinding.ItemFollowHorizontalBinding

class FocusItemAdapter(val itemList: List<ItemX>) :
    RecyclerView.Adapter<FocusItemAdapter.BindViewHolder>() {

    class BindViewHolder(var binding: ItemFollowHorizontalBinding) :
        RecyclerView.ViewHolder(binding.root) {
        fun bind(itemData: ItemX, holder: BindViewHolder) {
            binding.tvTitleFollow.text = itemData.data.title
            binding.tvTagFollow.text = itemData.data.description
            Glide.with(holder.itemView).load(itemData.data.cover.feed).centerCrop()
                .into(binding.ivCoverFeed)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindViewHolder {
        val binding =
            ItemFollowHorizontalBinding.inflate(LayoutInflater.from(parent.context), parent, false)

        return BindViewHolder(binding)
    }

    override fun onBindViewHolder(holder: BindViewHolder, position: Int) {
        //绑定每条数据
        val itemData = itemList[position]
        holder.bind(itemData, holder)
    }

    override fun getItemCount(): Int {
        return itemList.size
    }
}
